using Toast.Compression.Providers;
using Toast.Core;
using Toast.Core.Interfaces;

namespace Toast.Compression
{
    public class PackerCompression : IJavaScriptCompressionStrategy
    {
        #region IJavaScriptCompressionStrategy Members

        public string Compress(string script)
        {
            var packer = new ECMAScriptPacker(EncodingConvert(CompressionLevel), true, false);
            return packer.Pack(script);
        }

        public CompressionLevel CompressionLevel { get; set; }

        #endregion

        static ECMAScriptPacker.PackerEncoding EncodingConvert(CompressionLevel compressionLevel)
        {
            switch (compressionLevel)
            {
                case CompressionLevel.High:
                    return ECMAScriptPacker.PackerEncoding.HighAscii;
                case CompressionLevel.Mid:
                    return ECMAScriptPacker.PackerEncoding.Mid;
                case CompressionLevel.None:
                    return ECMAScriptPacker.PackerEncoding.None;
                default:
                    return ECMAScriptPacker.PackerEncoding.Normal;
            }
        }
    }
}